# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: osch <oliver at luced de>

pkgbase=lua-lanes
_rockname=${pkgbase#lua-}
pkgname=("$pkgbase" "lua51-$_rockname" "lua52-$_rockname" "lua53-$_rockname")
pkgname=lua-lanes
pkgver=3.16.2
pkgrel=1
_rockrel=0
pkgdesc='a lightweight, native, lazy evaluating multithreading library'
arch=(loong64 x86_64)
url="https://github.com/LuaLanes/$_rockname"
license=(MIT)
makedepends=(lua
             lua51
             lua52
             lua53
             luarocks)
_archive="$_rockname-$pkgver"
_rock="$_archive-$_rockrel.linux-$CARCH.rock"
source=("$url/archive/v$pkgver/$_archive.tar.gz")
sha256sums=('3af9e599877b7d41dea03a0180ad48c77ed324564ecb08a6e3b8d63612944194')

build() {
	cd "$_archive"
	for LUAVER in 5.{1,2,3,4}; do
		luarocks --lua-version "$LUAVER" \
			make --pack-binary-rock --deps-mode none -- "$_archive-$_rockrel.rockspec"
		install -Dm0644 -t "lua-$LUAVER/" "$_rock"
	done
}

_package() {
	cd "$_archive"
	depends=("${pkgname%-*}")
	luarocks --lua-version "$1" --tree "$pkgdir/usr/" \
		install --deps-mode none --no-manifest -- "lua-$1/$_rock"
	install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" COPYRIGHT
}

package_lua-lanes() {
	_package 5.4
}

package_lua53-lanes() {
	_package 5.3
}

package_lua52-lanes() {
	_package 5.2
}

package_lua51-lanes() {
	_package 5.1
}
